package com.stoken.web.control;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.stoken.domain.TravelLeaveMessage;
import com.stoken.service.TravelLeaveMessageService;
import com.stoken.service.TravelLeaveReplyService;

@Controller
@RequestMapping("/leaveReply")
public class TravelLeaveReplyControl {
	
	@Autowired
	private TravelLeaveReplyService travelLeaveReplyService;
	
	@Autowired
	private TravelLeaveMessageService travelLeaveMessageService;
	
//	/**
//	 * 加载留言管理页面
//	 * @return
//	 */
//	@RequestMapping("/backstage/loadLeaveMessagePage")
//	public String loadLeaveMessage(){
//		return "/backstage/leaveMessage/leaveMessage";		
//	}
//	
//	@RequestMapping("/backstage/leaveMessageData")
//	public String loadLeaveMeData(HttpServletRequest request,ModelMap modeMape){
//		//MemberBaseInfo mbi = (MemberBaseInfo) request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
//		Page<MemberLeaveMessage> pageData = new Page<MemberLeaveMessage>();
//		//给pageData设置参数
//		WebUtils.setPageDataParameter(request, pageData);
//		Compositor compositor = new Compositor("leaveTime",CompositorType.DESC);
//		pageData.setCompositor(compositor);
//		
//		pageData = memberLeaveMessageService.findAll(pageData);
//	    modeMape.addAttribute("pageData", pageData);
//	    
//	    Pagination page = new Pagination();
//		page.setIntTotalNum((int)pageData.getPagination().getTotalCount());
//		page.setCurpage(pageData.getPagination().getPageNo());
//		page.setPagenum(pageData.getPagination().getPageSize());
//		modeMape.addAttribute("pagination", page.showPages());
//		
//		return "/backstage/leaveMessage/leaveMessagePage";		
//	}
	
	@RequestMapping("/merchant/replay")
	public String loadLeaveReply(HttpServletRequest request,long id,ModelMap modeMape){		
		TravelLeaveMessage mbLeaveMessage = travelLeaveMessageService.get(id);
		if(mbLeaveMessage == null){
			return "/merchant/leaveMessage/leaveMessage";		
		}
		modeMape.addAttribute("mbLeaveMessage", mbLeaveMessage);
		return "/merchant/leaveMessage/replay";
		
	}
	
	@RequestMapping("/merchant/writeRplay")
	public String replayLeaveMessage(HttpServletRequest request,ModelMap modeMape,String reContext,long leaveId){
		if(StringUtils.isNotBlank(reContext)){
			travelLeaveReplyService.writeLeaveMessage(reContext, leaveId);
		}
		return "/merchant/leaveMessage/leaveMessage";		
	}
	
	
}
